<!DOCTYPE html>
<html lang="${LANG}" class="dark">

<head>
    <meta charset="UTF-8">
    <title>QBT_TR(New rule name)QBT_TR[CONTEXT=AutomatedRssDownloader]</title>
    <link rel="stylesheet" href="css/style.css?v=${CACHEID}" type="text/css">
    <script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
    <script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>
    <script>
        "use strict";

        window.addEventListener("DOMContentLoaded", (event) => {
            window.addEventListener("keydown", (event) => {
                switch (event.key) {
                    case "Enter":
                        event.preventDefault();
                        document.getElementById("submitButton").click();
                        break;
                    case "Escape":
                        event.preventDefault();
                        window.parent.qBittorrent.Client.closeFrameWindow(window);
                        break;
                }
            });

            document.getElementById("name").focus();
            document.getElementById("submitButton").addEventListener("click", (e) => {
                e.preventDefault();
                e.stopPropagation();

                // check field
                const name = document.getElementById("name").value.trim();
                if (name === "") {
                    alert("QBT_TR(Name cannot be empty)QBT_TR[CONTEXT=HttpServer]");
                    return;
                }
                document.getElementById("submitButton").disabled = true;

                fetch("api/v2/rss/setRule", {
                        method: "POST",
                        body: new URLSearchParams({
                            ruleName: name,
                            ruleDef: "{}"
                        })
                    })
                    .then((response) => {
                        if (!response.ok)
                            return;

                        window.parent.qBittorrent.RssDownloader.updateRulesList();
                        window.parent.qBittorrent.Client.closeFrameWindow(window);
                    });
            });
        });
    </script>
</head>

<body>
    <div style="padding: 10px 10px 0px 10px;">
        <label for="name">QBT_TR(Please type the name of the new download rule.)QBT_TR[CONTEXT=AutomatedRssDownloader]</label>
        <input type="text" id="name" style="width: 320px;">
        <div style="text-align: center; padding-top: 10px;">
            <input type="button" value="QBT_TR(OK)QBT_TR[CONTEXT=HttpServer]" id="submitButton">
        </div>
    </div>
</body>

</html>
